package cn.tedu.bonfire.front.content.dao.persist.repository.impl;

import cn.tedu.bonfire.common.pojo.vo.PageData;
import cn.tedu.bonfire.common.util.PageInfoToPageDataConverter;
import cn.tedu.bonfire.front.content.dao.persist.mapper.CategoryMapper;
import cn.tedu.bonfire.front.content.dao.persist.repository.ICategoryRepository;
import cn.tedu.bonfire.front.content.pojo.vo.CategoryListItemVO;
import cn.tedu.bonfire.front.content.pojo.vo.CategoryStandardVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CategoryRepository implements ICategoryRepository {
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public CategoryStandardVO getStandardById(Long id){
        return categoryMapper.getStandardById(id);
    }

    @Override
    public PageData<CategoryListItemVO> listByParent(Long parentId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<CategoryListItemVO> list = categoryMapper.listByParent(parentId);
        PageInfo<CategoryListItemVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    @Override
    public List<CategoryListItemVO> list() {
        return categoryMapper.list();
    }

}
